perm filename FREE.LST[HAL,HE] blob sn#119201 filedate 1974-09-12 generic text, type T, neo UTF8
	PALX 222	09/12/74  01:24:20	PAGE 1
	FREE PAL[HAL,HE]	PAGE 2 	Small block allocator

RESTRT	12242	2	25	MISSING COMMA
RESTRT		12242	2	25	NULL IMMED. OPERAND
	012242	004067	165532		RESTRT:	JSR FRINIT	;Reestablish free storage
	PALX 222	09/12/74  01:24:20	PAGE 2
	FREE PAL[HAL,HE]	PAGE 1 	

				COMMENT ⊗   VALID 00002 PAGES
				C REC  PAGE   DESCRIPTION
				C00001 00001
				C00002 00002	Test of free storage routines
				C00010 ENDMK
					C⊗;
	PALX 222	09/12/74  01:24:20	PAGE 3
	FREE PAL[HAL,HE]	PAGE 2 	

					;Test of free storage routines
					
					.INSRT HALHED.PAL[HAL,HE]
	PALX 222	09/12/74  01:24:20	PAGE 4
	HALHED PAL[HAL,HE]	PAGE 1 	

				COMMENT ⊗   VALID 00004 PAGES
				C REC  PAGE   DESCRIPTION
				C00001 00001
				C00002 00002	.SBTTL	DEFS -- standard definitions for HAL runtime routines
				C00004 00003	routine calling and defining macros.
				C00006 00004	Graph structure definitions
				C00007 ENDMK
					C⊗;
	PALX 222	09/12/74  01:24:20	PAGE 5
	HALHED PAL[HAL,HE]	PAGE 2 	DEFS -- standard definitions for HAL runtime routines

					.SBTTL	DEFS -- standard definitions for HAL runtime routines
					
					; PROGRAM DEFINITIONS
					
		000004			ERRTRP=4		;time out and error trap
		000010			ILGINS=10		;illegal instruction
		000104			CLKTRP=104		;clock trap
		050000			RUG=50000		;Restart of RUG
		177776			PS=177776		;processor status word
		177560			KBIS=177560		;keyboard input status
		177562			KBIR=177562		;keyboard input register
		177564			KBOS=177564		;keyboard output status
		177566			KBOR=177566		;keyboard output register
		172544			CLKCNT=172544		;clock counter
		172542			CLKSET=172542		;clock set register
		172540			CLKS=172540		;clock status
					
		000500			STRT11=500		;starting address of program
		000150			IBUF=150		;start of input buffer from 11
		000160			OBUF=160		;start of output buffer to 11 
		077776			HCOR=77776		;highest useable word in core
					
					
					;REGISTER DEFINITIONS
					
		000007			PC=%7			;program counter
		000006			SP=%6			;stack pointer
		000005			RF=%5			;Display pointer
		000004			R4=%4			;Saved across procedure calls
		000003			R3=%3			;Saved across procedure calls
		000002			R2=%2			;Saved across procedure calls
		000001			R1=%1			;temp
		000000			R0=%0			;temp
					
					;MARK DEFINITIONS
		006400			MARK0 = 6400		;MARK 0
		006401			MARK1 = 6401		;MARK 1
		006402			MARK2 = 6402		;ETC.
		006403			MARK3 = 6403
		006404			MARK4 = 6404
		006405			MARK5 = 6405
	PALX 222	09/12/74  01:24:20	PAGE 6
	HALHED PAL[HAL,HE]	PAGE 3 	DEFS -- standard definitions for HAL runtime routines

					;routine calling and defining macros.
					;Coded by RHT 9/74.
					
					;This should be used at the start of routines which reference
					;	parameters off the RF stack.  It gives the parameters
					;	symbolic names for clarity of coding.
					;For example,
					;
					;	ROUTINE FOO,<A,B>
					;
					;Goes to
					;
					;	A==4
					;	B==2
					;FOO:
					
					.MACRO ROUTINE ID,ARGS
					   .IFNB ARGS
						NNNN==0
						.IRP II,<ARGS>		;Raise NNNN to twice the number of args.
							NNNN==NNNN+2
							.ENDM
						.IRP II,<ARGS>		;Assign each arg NNNN and decrease same.
							II == NNNN
							NNNN == NNNN-2
							.ENDM
					   .ENDC
					ID:
						.ENDM
					
					;This is useful in calling rountines which reference parameters off
					;	the RF stack.  It sets up the stack properly, but does not
					;	save R0 or R1.
					
					.MACRO CALL ID,ARGS
						MOV	RF,-(SP)	;Save RF
						NNNN == 6400		;This is a MARK 0 instruction
					  .IFNB ARGS
					   .IRP II,<ARGS>
						MOV	II,-(SP);Push an argument
						NNNN == NNNN+1	;Make NNNN the next MARK instruction.
					    .ENDM
					  .ENDC
						MOV	#NNNN,-(SP)	;Push the mark instruction.
						MOV	SP,RF		;Set up the display in RF.
						JSR	PC,ID		;Call the routine
						.ENDM
	PALX 222	09/12/74  01:24:20	PAGE 7
	HALHED PAL[HAL,HE]	PAGE 4 	DEFS -- standard definitions for HAL runtime routines

					;Graph structure definitions
					;RHT 9/74
					
					.MACRO	XX SYM			;Just gives SYM the next number.
						SYM == II
						II == II+2
						.ENDM
					
					;CELL LINKS
		000000				II==0
						XX	DATUM
		000000				DATUM == II
		000002				II == II+2
						XX	LINKF
		000002				LINKF == II
		000004				II == II+2
						XX	LINKB
		000004				LINKB == II
		000006				II == II+2
					
					;GRAPH NODES
		000000				II==0
						XX	NXTGN		;CHAIN OF ALL GNODES IN THE WORLD
		000000				NXTGN == II
		000002				II == II+2
						XX	PRVGN
		000002				PRVGN == II
		000004				II == II+2
						XX	INVMRK		;USED AS FLAG
		000004				INVMRK == II
		000006				II == II+2
						XX	GNVAL		;POINTER AT VALUE
		000006				GNVAL == II
		000010				II == II+2
						XX	GNDEPS		;DEPENDENT GRAPH NODES
		000010				GNDEPS == II
		000012				II == II+2
						XX	GNCLCS		;CALCULATOR LIST (DBL LINKED)
		000012				GNCLCS == II
		000014				II == II+2
						XX	GNCHGS		;CHANGE LIST
		000014				GNCHGS == II
		000016				II == II+2
					
					;CALCULATOR CELL
		000000				II==0
						XX	NXTCLC		;LIST LINK
		000000				NXTCLC == II
		000002				II == II+2
	PALX 222	09/12/74  01:24:20	PAGE 8
	HALHED PAL[HAL,HE]	PAGE 4.1 	DEFS -- standard definitions for HAL runtime routines

						XX	NEEDED		;LIST OF NEEDED NODES
		000002				NEEDED == II
		000004				II == II+2
						XX	FORM		;SOME SORT OF CODE TO EVAL
		000004				FORM == II
		000006				II == II+2
					
					;CHANGER CELL
		000000				II==0
						XX	NXTCHG
		000000				NXTCHG == II
		000002				II == II+2
						XX	CHGCOD
		000002				CHGCOD == II
		000004				II == II+2
					
	PALX 222	09/12/74  01:24:20	PAGE 9
	FREE PAL[HAL,HE]	PAGE 2.1 	DEFS -- standard definitions for HAL runtime routines

		000500			.=STRT11
					.INSRT HALIO.PAL[HAL,HE]
	PALX 222	09/12/74  01:24:20	PAGE 10
	HALIO PAL[HAL,HE]	PAGE 1 	DEFS -- standard definitions for HAL runtime routines

				COMMENT ⊗   VALID 00003 PAGES
				C REC  PAGE   DESCRIPTION
				C00001 00001
				C00002 00002	.SBTTL	TTY output routines
				C00005 00003	.SBTTL Useful macros for use of I/O routines
				C00007 ENDMK
					C⊗;
	PALX 222	09/12/74  01:24:20	PAGE 11
	HALIO PAL[HAL,HE]	PAGE 2 	TTY output routines

					.SBTTL	TTY output routines
					;  Modified 5-Sep-74 by RF.  Originally written by KKP.
					
					;	Output a string, ending with a zero character. Pointer to start
					;	of string in R0.  Called in "simple" style.
					
		000500			.EVEN
	000500	010001			TYPSTR:	MOV R0,R1	;R1 ← LOC[STRING]
	000502	112100				MOVB (R1)+,R0	;R0 ← first byte of string
	000504	004767	000056		TSLOOP:	JSR PC,TYPCHR	;Type this one character
	000510	112100				MOVB (R1)+,R0	;R0 ← Next byte of string
	000512	001374				BNE TSLOOP	;If more to come, repeat.
	000514	000207				RTS PC		;Done
					
					
					; Routines to output numbers.  Argument in R0.
					; TYPDEC outputs in base 10, and TYPOCT in base 8.
					; Both use TYPDIG as a subroutine, putting the digit
					;	in R0.
					; TYPCHR is a general purpose character output routine.
					
		000516			.EVEN
	000516	012767	000012	000020	TYPDEC:	MOV #12,RADIX	;To output in base 10
	000524	000404				BR TYPDIG	;Go type it.
	000526	012767	000010	000010	TYPOCT:	MOV #8,RADIX	;To output in base 8.
	000534	000400				BR TYPDIG	;Go type it.
	000536	010001			TYPDIG:	MOV R0,R1	;Need dividend in R1, with R0 clear.
	000540	005000				CLR R0		;Clear upper half of dividend.
	000542	071027				DIV (PC)+,R0	;Divide argument in R0, R1 by radix.
	000544	000012			RADIX:	12		;Starts out in decimal.
	000546	001404				BEQ TYPOUT	;If quotient zero, then can print.
	000550	010146				MOV R1,-(SP)	;Else stack quotient
	000552	004767	177760			JSR PC,TYPDIG	;Recursive call.
	000556	012601				MOV (SP)+,R1	;Unstack last quotient
	000560	062701	000060		TYPOUT:	ADD #'0,R1	;Form TTY code for digit
	000564	010100				MOV R1,R0	;Need argument for TYPCHR in R0.
	000566	105767	176772		TYPCHR:	TSTB KBOS	;Is TTY available?
	000572	100375				BPL TYPCHR	;No.  Busy wait for it.
	000574	110067	176766			MOVB R0,KBOR	;Yes.  Output a byte to it.
	000600	022700	000012			CMP #12,R0	;Was it a line feed?
	000604	001007				BNE TYPRET	;If not that code, then done.
	000606	005000				CLR R0		;Otherwise, output 3 nulls.
	000610	004767	177752			JSR PC,TYPCHR	;
	000614	004767	177746			JSR PC,TYPCHR	;
	000620	004767	177742			JSR PC,TYPCHR	;
	000624	000207			TYPRET:	RTS PC		;Return.
					
					
	PALX 222	09/12/74  01:24:20	PAGE 12
	HALIO PAL[HAL,HE]	PAGE 3 	Useful macros for use of I/O routines

					.SBTTL Useful macros for use of I/O routines
					
					.MACRO	 OUTSTR B	;Type string starting at B.
						MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
						MOV R1,-(SP)	;Save R1.
						MOV #B,R0	;Load up the string to be output
						JSR PC,TYPSTR	;Call the string output utility routine.
						MOV (SP)+,R1	;Restore R1.
						MOV (SP)+,R2	;Restore R2.
						.ENDM
					
					.MACRO ASCIE STR
						.ASCIZ STR
						.EVEN
						.ENDM
					
					.MACRO	CRLF
						OUTSTR CRLFX	;Carriage return, line feed.
						.ENDM
					
	000626	   015		
	000627	   012			CRLFX:	.ASCIZ /
	000630	   000		
					/
					
				RUGMES:	ASCIE </π
				--YOU'RE UNDER THE RUG
					π/>
	000631	   007		
	000632	   015		
	000633	   012				.ASCIZ /π
	000634	   055		
	000635	   055		
	000636	   131		
	000637	   117		
	000640	   125		
	000641	   047		
	000642	   122		
	000643	   105		
	000644	   040		
	000645	   125		
	000646	   116		
	000647	   104		
	000650	   105		
	000651	   122		
	000652	   040		
	000653	   124		
	000654	   110		
	000655	   105		
	PALX 222	09/12/74  01:24:20	PAGE 13
	HALIO PAL[HAL,HE]	PAGE 3.1 	Useful macros for use of I/O routines

	000656	   040		
	000657	   122		
	000660	   125		
	000661	   107		
	000662	   015		
	000663	   012			--YOU'RE UNDER THE RUG
	000664	   007		
	000665	   000		
					π/
		000666				.EVEN
		000666			.EVEN
					
					.MACRO	HALERR MES	;Bad error.  Type message, call RUG.
						CRLF		;
						OUTSTR MES	;
						OUTSTR RUGMES	;
						JMP RUG		;Go directly to RUG.
						BR .-4		;In case we return.
						.ENDM
					
					.MACRO	TTYIN B		;To read in a word.
						TSTB KBIS	;Is keyboard ready?
						.BEQ .-4	;No.  Busy wait.
						MOV KBIR,B	;Yes.  Read a word.
						BIC #200,B	;Mask off a bit.
						.ENDM
					
	PALX 222	09/12/74  01:24:20	PAGE 14
	HALTST PAL[HAL,HE]	PAGE 2.2 	Useful macros for use of I/O routines

					.INSRT HALTST.PAL[HAL,HE]
	PALX 222	09/12/74  01:24:20	PAGE 15
	HALTST PAL[HAL,HE]	PAGE 1 	Useful macros for use of I/O routines

				COMMENT ⊗   VALID 00005 PAGES
				C REC  PAGE   DESCRIPTION
				C00001 00001
				C00002 00002	.SBTTL Large block allocator
				C00006 00003	 Routine to release free storage.  R0=LOC[LTAG[BLOCK]] + 1.
				C00009 00004	.SBTTL Small block allocator
				C00012 00005	Routine to allocate an item of size R0 words.  Returns location
				C00017 ENDMK
					C⊗;
	PALX 222	09/12/74  01:24:20	PAGE 16
	HALTST PAL[HAL,HE]	PAGE 2 	Large block allocator

					.SBTTL Large block allocator
					
					; Assembly variables
		004000			FREL = 4000		;Test of small amount.  Maximum = 40000 (IN WORDS!)
					
					; Free storage block
		000666			.EVEN
	000666	000672			FREEPT:	FREEST
	000670	177777				-1		;Left bdry tag is negative.
	000672	010000			FREEST:	FREL*2		;Beginning of free storage.  Boundary tag.
		010670				.BLKW	FREL-2	;
	010670	010000			FREEND:	FREL*2		;End of free storage.  Boundary tag.
	010672	177777				-1		;Right bdry tag is negative.
					
					; Routine to assign storage.  Amount of words requested in R0.
					;	Location of first word in block (not the boundary tag) returned
					;	in R0.
					;  The boundary tag method described in Knuth I.2.5 is
					;	used.  Each block of storage has a boundary tag at
					;	each end, with identical contents:  The number
					;	of bytes in the whole area if available, and the opposite
					;	of that if busy.  Artificial busy areas above and below
					;	free storage.
	010674	010246			GTFREE:	MOV R2,-(SP)	;Save R2 on stack.
	010676	006300				ASL R0		;Convert words to bytes
	010700	002454				BLT FREERR	;Asked for negative number of words.
	010702	062700	000004			ADD #4, R0	;Need 2 extra words for boundary tags
	010706	016701	167754			MOV FREEPT, R1	;R1 ← running LOC[LTAG[*]]
	010712	020127	010670		FRTRY:	CMP R1,#FREEND	;Are we off the end of free storage?
	010716	101402				BLOS FR2	;No.
	010720	012701	000672			MOV #FREEST,R1	;Yes.  Reset pointer to beginning.
	010724	021100			FR2:	CMP (R1),R0	;Do we have enough room here?
	010726	002011				BGE FFOUND	;Yes
	010730	005711				TST (R1)	;No.  Is this area busy?  If so, its count is negative.
	010732	002002				BGE FRPOS	;No.
	010734	161101				SUB (R1),R1	;Yes.  R1 ← LOC[LTAG[next] by subtraction.
	010736	000401				BR  FR1
	010740	061101			FRPOS:	ADD (R1),R1	;R1 ← LOC[LTAG[next] by addition.
	010742	020167	167720		FR1:	CMP R1,FREEPT	;Have we cycled all through free storage
	010746	001464				BEQ FROVFL	;Yes.  No room!
	010750	000760				BR  FRTRY	;No.  Try again.
	010752	001422			FFOUND:	BEQ FEXACT	;If 0, then exact fit.
	010754	010102				MOV R1,R2	;Divide the found block into FOUND and HOLE.
								;Thus, R1 = LOC[LTAG[FOUND]].
	010756	060002				ADD R0,R2	;R2 ← LOC[LTAG[HOLE]]
	010760	005400				NEG R0		;R0 ← negative (busy) count of FOUND.
	010762	010062	177776			MOV R0,-2(R2)	;RTAG[FOUND] ← new FOUND count.
	010766	010046				MOV R0,-(SP)	;Save R0.
	010770	061100				ADD (R1),R0	;R0 ← new HOLE count.
	PALX 222	09/12/74  01:24:20	PAGE 17
	HALTST PAL[HAL,HE]	PAGE 2.1 	Large block allocator

	010772	010012				MOV R0,(R2)	;LTAG[HOLE] ← new HOLE count.
	010774	010267	167666			MOV R2,FREEPT	;Free pointer ← LOC[LTAG[HOLE]]
	011000	010102				MOV R1,R2	;
	011002	005742				TST -(R2)	;
	011004	061102				ADD (R1),R2	;R2 ← LOC[RTAG[HOLE]].
	011006	010012				MOV R0,(R2)	;RTAG[HOLE] ← new HOLE count.
	011010	012621				MOV (SP)+,(R1)+	;LTAG[FOUND] ← new FOUND count.
	011012	010100			FRRET:	MOV R1,R0	;R0 (result) ← LOC[LTAG[FOUND]] + 1.
	011014	012602				MOV (SP)+,R2	;Restore R2
	011016	000207				RTS PC		;Done.
	011020	010102			FEXACT:	MOV R1,R2	;
	011022	061102				ADD (R1),R2	;R2 ← LOC[RTAG[FOUND]]
	011024	005421				NEG (R1)+	;LTAG[FOUND] ← new (busy) count.
	011026	005442				NEG -(R2)	;RTAG[FOUND] ← new (busy) count.
	011030	000770				BR FRRET	;Ready to return
					FREERR:	HALERR FRMS1
						CRLF		;
						OUTSTR CRLFX	;Carriage return, line feed.
	011032	010046				MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	011034	010146				MOV R1,-(SP)	;Save R1.
	011036	012700	000626			MOV #CRLFX,R0	;Load up the string to be output
	011042	004767	167432			JSR PC,TYPSTR	;Call the string output utility routine.
	011046	012601				MOV (SP)+,R1	;Restore R1.
	011050	012602				MOV (SP)+,R2	;Restore R2.
						OUTSTR FRMS1	;
	011052	010046				MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	011054	010146				MOV R1,-(SP)	;Save R1.
	011056	012700	011206			MOV #FRMS1,R0	;Load up the string to be output
	011062	004767	167412			JSR PC,TYPSTR	;Call the string output utility routine.
	011066	012601				MOV (SP)+,R1	;Restore R1.
	011070	012602				MOV (SP)+,R2	;Restore R2.
						OUTSTR RUGMES	;
	011072	010046				MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	011074	010146				MOV R1,-(SP)	;Save R1.
	011076	012700	000631			MOV #RUGMES,R0	;Load up the string to be output
	011102	004767	167372			JSR PC,TYPSTR	;Call the string output utility routine.
	011106	012601				MOV (SP)+,R1	;Restore R1.
	011110	012602				MOV (SP)+,R2	;Restore R2.
	011112	000167	036662			JMP RUG		;Go directly to RUG.
	011116	000775				BR .-4		;In case we return.
					FROVFL:	HALERR FRMS2
						CRLF		;
						OUTSTR CRLFX	;Carriage return, line feed.
	011120	010046				MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	011122	010146				MOV R1,-(SP)	;Save R1.
	011124	012700	000626			MOV #CRLFX,R0	;Load up the string to be output
	011130	004767	167344			JSR PC,TYPSTR	;Call the string output utility routine.
	011134	012601				MOV (SP)+,R1	;Restore R1.
	011136	012602				MOV (SP)+,R2	;Restore R2.
	PALX 222	09/12/74  01:24:20	PAGE 18
	HALTST PAL[HAL,HE]	PAGE 2.2 	Large block allocator

						OUTSTR FRMS2	;
	011140	010046				MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	011142	010146				MOV R1,-(SP)	;Save R1.
	011144	012700	011262			MOV #FRMS2,R0	;Load up the string to be output
	011150	004767	167324			JSR PC,TYPSTR	;Call the string output utility routine.
	011154	012601				MOV (SP)+,R1	;Restore R1.
	011156	012602				MOV (SP)+,R2	;Restore R2.
						OUTSTR RUGMES	;
	011160	010046				MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	011162	010146				MOV R1,-(SP)	;Save R1.
	011164	012700	000631			MOV #RUGMES,R0	;Load up the string to be output
	011170	004767	167304			JSR PC,TYPSTR	;Call the string output utility routine.
	011174	012601				MOV (SP)+,R1	;Restore R1.
	011176	012602				MOV (SP)+,R2	;Restore R2.
	011200	000167	036574			JMP RUG		;Go directly to RUG.
	011204	000775				BR .-4		;In case we return.
					FRMS1:	ASCIE </YOU ASKED FOR NEGATIVE AMOUNT OF FREE SPACE/>
	011206	   131		
	011207	   117		
	011210	   125		
	011211	   040		
	011212	   101		
	011213	   123		
	011214	   113		
	011215	   105		
	011216	   104		
	011217	   040		
	011220	   106		
	011221	   117		
	011222	   122		
	011223	   040		
	011224	   116		
	011225	   105		
	011226	   107		
	011227	   101		
	011230	   124		
	011231	   111		
	011232	   126		
	011233	   105		
	011234	   040		
	011235	   101		
	011236	   115		
	011237	   117		
	011240	   125		
	011241	   116		
	011242	   124		
	011243	   040		
	011244	   117		
	011245	   106		
	PALX 222	09/12/74  01:24:20	PAGE 19
	HALTST PAL[HAL,HE]	PAGE 2.3 	Large block allocator

	011246	   040		
	011247	   106		
	011250	   122		
	011251	   105		
	011252	   105		
	011253	   040		
	011254	   123		
	011255	   120		
	011256	   101		
	011257	   103		
	011260	   105		
	011261	   000		
						.ASCIZ /YOU ASKED FOR NEGATIVE AMOUNT OF FREE SPACE/
		011262				.EVEN
					FRMS2:	ASCIE /FREE STORAGE EXHAUSTED/
	011262	   106		
	011263	   122		
	011264	   105		
	011265	   105		
	011266	   040		
	011267	   123		
	011270	   124		
	011271	   117		
	011272	   122		
	011273	   101		
	011274	   107		
	011275	   105		
	011276	   040		
	011277	   105		
	011300	   130		
	011301	   110		
	011302	   101		
	011303	   125		
	011304	   123		
	011305	   124		
	011306	   105		
	011307	   104		
	011310	   000		
						.ASCIZ /FREE STORAGE EXHAUSTED/
		011312				.EVEN
					
					
	PALX 222	09/12/74  01:24:20	PAGE 20
	HALTST PAL[HAL,HE]	PAGE 3 	Large block allocator

					; Routine to release free storage.  R0=LOC[LTAG[BLOCK]] + 1.
					; Call the currently released block BLOCK, the adjacent one
					;	below LOW, and the adjacent one above HIGH.
	011312	014001			RLFREE:	MOV -(R0),R1	;R1 ← LOC[LTAG[BLOCK]]
	011314	002071				BGE RLFER2	;Can't release available space.
	011316	010001				MOV R0,R1	;R1 ← LOC[LTAG[BLOCK]]
	011320	161000				SUB (R0),R0	;R0 ← LOC[LTAG[HIGH]]
	011322	021160	177776			CMP (R1),-2(R0)	;Do the two bdry tags agree?
	011326	001031				BNE RLFER1	;No.  Storage munged!!
	011330	005411				NEG (R1)	;Count is now positive in LTAG[BLOCK].
	011332	005761	177776			TST -2(R1)	;Is LOW available?
	011336	002411				BLT MERGR	;No.  Cannot merge left.
	011340	066111	177776			ADD -2(R1),(R1)	;Yes.  LTAG[BLOCK] ← New count
	011344	011160	177776			MOV (R1),-2(R0)	;RTAG[BLOCK] ← New count
	011350	010001				MOV R0,R1	;
	011352	166101	177776			SUB -2(R1),R1	;R1 ← LOC[LTAG[LOW]]
	011356	016011	177776			MOV -2(R0),(R1)	;LTAG[LOW] ← New count
								;At this point, call LOW&BLOCK = BLOCK.
	011362	005710			MERGR:	TST (R0)	;Is HIGH available?
	011364	002407				BLT RLRET	;No.  Prepare to return.
	011366	061011				ADD (R0),(R1)	;LTAG[BLOCK] ← New count
	011370	026700	167272			CMP FREEPT,R0	;Will FREEPT point into a vacuum?
	011374	001002				BNE RL1		;No.
	011376	010167	167264			MOV R1,FREEPT	;Yes.  Reset FREEPT ← LOC[LTAG[BLOCK]]
	011402	061000			RL1:	ADD (R0),R0	;R0 ← LOC[RTAG[HIGH]] + 1
								;At this point, call BLOCK&HIGH = BLOCK.
	011404	011160	177776		RLRET:	MOV (R1),-2(R0)	;RTAG[BLOCK] ← New count
	011410	000207				RTS PC		;Done.
					RLFER1:	HALERR RLMS1
						CRLF		;
						OUTSTR CRLFX	;Carriage return, line feed.
	011412	010046				MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	011414	010146				MOV R1,-(SP)	;Save R1.
	011416	012700	000626			MOV #CRLFX,R0	;Load up the string to be output
	011422	004767	167052			JSR PC,TYPSTR	;Call the string output utility routine.
	011426	012601				MOV (SP)+,R1	;Restore R1.
	011430	012602				MOV (SP)+,R2	;Restore R2.
						OUTSTR RLMS1	;
	011432	010046				MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	011434	010146				MOV R1,-(SP)	;Save R1.
	011436	012700	011566			MOV #RLMS1,R0	;Load up the string to be output
	011442	004767	167032			JSR PC,TYPSTR	;Call the string output utility routine.
	011446	012601				MOV (SP)+,R1	;Restore R1.
	011450	012602				MOV (SP)+,R2	;Restore R2.
						OUTSTR RUGMES	;
	011452	010046				MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	011454	010146				MOV R1,-(SP)	;Save R1.
	011456	012700	000631			MOV #RUGMES,R0	;Load up the string to be output
	011462	004767	167012			JSR PC,TYPSTR	;Call the string output utility routine.
	PALX 222	09/12/74  01:24:20	PAGE 21
	HALTST PAL[HAL,HE]	PAGE 3.1 	Large block allocator

	011466	012601				MOV (SP)+,R1	;Restore R1.
	011470	012602				MOV (SP)+,R2	;Restore R2.
	011472	000167	036302			JMP RUG		;Go directly to RUG.
	011476	000775				BR .-4		;In case we return.
					RLFER2:	HALERR RLMS2
						CRLF		;
						OUTSTR CRLFX	;Carriage return, line feed.
	011500	010046				MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	011502	010146				MOV R1,-(SP)	;Save R1.
	011504	012700	000626			MOV #CRLFX,R0	;Load up the string to be output
	011510	004767	166764			JSR PC,TYPSTR	;Call the string output utility routine.
	011514	012601				MOV (SP)+,R1	;Restore R1.
	011516	012602				MOV (SP)+,R2	;Restore R2.
						OUTSTR RLMS2	;
	011520	010046				MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	011522	010146				MOV R1,-(SP)	;Save R1.
	011524	012700	011635			MOV #RLMS2,R0	;Load up the string to be output
	011530	004767	166744			JSR PC,TYPSTR	;Call the string output utility routine.
	011534	012601				MOV (SP)+,R1	;Restore R1.
	011536	012602				MOV (SP)+,R2	;Restore R2.
						OUTSTR RUGMES	;
	011540	010046				MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	011542	010146				MOV R1,-(SP)	;Save R1.
	011544	012700	000631			MOV #RUGMES,R0	;Load up the string to be output
	011550	004767	166724			JSR PC,TYPSTR	;Call the string output utility routine.
	011554	012601				MOV (SP)+,R1	;Restore R1.
	011556	012602				MOV (SP)+,R2	;Restore R2.
	011560	000167	036214			JMP RUG		;Go directly to RUG.
	011564	000775				BR .-4		;In case we return.
	011566	   122		
	011567	   114		
	011570	   106		
	011571	   122		
	011572	   105		
	011573	   105		
	011574	   040		
	011575	   106		
	011576	   105		
	011577	   101		
	011600	   122		
	011601	   123		
	011602	   040		
	011603	   106		
	011604	   122		
	011605	   105		
	011606	   105		
	011607	   040		
	011610	   123		
	011611	   124		
	PALX 222	09/12/74  01:24:20	PAGE 22
	HALTST PAL[HAL,HE]	PAGE 3.2 	Large block allocator

	011612	   117		
	011613	   122		
	011614	   101		
	011615	   107		
	011616	   105		
	011617	   040		
	011620	   111		
	011621	   123		
	011622	   040		
	011623	   127		
	011624	   111		
	011625	   120		
	011626	   105		
	011627	   104		
	011630	   040		
	011631	   117		
	011632	   125		
	011633	   124		
	011634	   000		
					RLMS1:	.ASCIZ /RLFREE FEARS FREE STORAGE IS WIPED OUT/
					RLMS2:	ASCIE /ATTEMPT TO FREE ALREADY AVAILABLE SPACE/
	011635	   101		
	011636	   124		
	011637	   124		
	011640	   105		
	011641	   115		
	011642	   120		
	011643	   124		
	011644	   040		
	011645	   124		
	011646	   117		
	011647	   040		
	011650	   106		
	011651	   122		
	011652	   105		
	011653	   105		
	011654	   040		
	011655	   101		
	011656	   114		
	011657	   122		
	011660	   105		
	011661	   101		
	011662	   104		
	011663	   131		
	011664	   040		
	011665	   101		
	011666	   126		
	011667	   101		
	011670	   111		
	PALX 222	09/12/74  01:24:20	PAGE 23
	HALTST PAL[HAL,HE]	PAGE 3.3 	Large block allocator

	011671	   114		
	011672	   101		
	011673	   102		
	011674	   114		
	011675	   105		
	011676	   040		
	011677	   123		
	011700	   120		
	011701	   101		
	011702	   103		
	011703	   105		
	011704	   000		
						.ASCIZ /ATTEMPT TO FREE ALREADY AVAILABLE SPACE/
		011706				.EVEN
	PALX 222	09/12/74  01:24:20	PAGE 24
	HALTST PAL[HAL,HE]	PAGE 4 	Small block allocator

					.SBTTL Small block allocator
					;Coded by RF, 10-Sept-1974
					
					;For small items like value cells, typically ranging in size
					;from 1 to 20 words, many of which are needed, there is a 
					;small block allocator.  Sixteen items of like size are
					;allocated simultaneously with GTFREE when needed.  SZHH points
					;to a the size header for the smallest size currently being
					;used.  (One efficiency not currently programmed in is
					;to have this initially point to a size header for an impossible
					;large size item.)  Each size has its own header, pointing
					;down a list of small blocks which have been allocated for this
					;size.  Each block holds the 16 items.
					
					;Global, pointing to smallest size header.
		011710			SZHH:	.BLKW 1		;Size header Header.
					
					;Size header.  Each small block size has one of these.
		000000				II == 0
						XX  NXTSH	;Next size header, for bigger blocks. (Must be first field)
		000000				NXTSH == II
		000002				II == II+2
						XX  SIZE	;Size of item in small block in WORDS.
		000002				SIZE == II
		000004				II == II+2
						XX  NALLOC	;Number of allocated blocks.
		000004				NALLOC == II
		000006				II == II+2
						XX  BLKLST	;Points to first small block of this size.
		000006				BLKLST == II
		000010				II == II+2
		000004				SIZSH = II/2	;How long a size header is in WORDS.
					
					;Small block.  Each one holds 16 items, as well as this info:
		000000				II == 0
						XX  NEXTB	;Next block of this size. (Must be first field)
		000000				NEXTB == II
		000002				II == II+2
						XX  MASK	;Each bit for one item.  0=free; 1=busy.
		000002				MASK == II
		000004				II == II+2
						XX  FRBIT	;Rotating bit.  Points to last assigned place.
		000004				FRBIT == II
		000006				II == II+2
						XX  WORD0	;First word of 16*SIZE words.
		000006				WORD0 == II
		000010				II == II+2
		000004				SIZBLH = II/2	;How long a block header is in WORDS.
					
	PALX 222	09/12/74  01:24:20	PAGE 25
	HALTST PAL[HAL,HE]	PAGE 5 	Small block allocator

					;Routine to allocate an item of size R0 words.  Returns location
					;	of item found in R0.
	011710	010246			GTITEM:	MOV R2,-(SP)	;Save R2.
	011712	010346				MOV R3,-(SP)	;Save R3.
	011714	012703	011706			MOV #SZHH,R3	;R3 ← LOC[SZHH].  Used to link in new.
	011720	016301	000000			MOV NXTSH(r3),R1	;R1 ← LOC[first size header]
	011724	001411				BEQ GTNWSH	;If 0, then need new size header.
	011726	016102	000002		GT1:	MOV SIZE(R1),R2	;R2 ← size of current size header in words.
	011732	020200				CMP R2,R0	;Is this the size we want?
	011734	001427				BEQ GTSZFD	;Yes.  We found the size.
	011736	003004				BGT GTNWSH	;No, too large.  Need new size header.
	011740	010103				MOV R1,R3	;No, too small. R3 ← LOC[too small size header]
	011742	016101	000000			MOV NXTSH(R1),R1 ;R1 ← LOC[next size header]
	011746	001367				BNE GT1		;If there is one, try again.
	011750	010046			GTNWSH:	MOV R0,-(SP)	;Save R0.
	011752	010146				MOV R1,-(SP)	;Save R1.
	011754	012700	000004			MOV #SIZSH,R0	;R0 ← Number of words needed for a size header.
	011760	004767	176710			JSR PC,GTFREE	;Get a block of that size.
	011764	010001				MOV R0,R1	;R1 ← LOC[new size header]
	011766	012661	000000			MOV (SP)+,NXTSH(R1) ;NXTSH[new size header] ← LOC[next size header]
	011772	010163	000000			MOV R1,NXTSH(R3);NXTSH[previous size header] ← LOC[new size header]
	011776	012600				MOV (SP)+,R0	;Restore R0 ← size desired in words.
	012000	010061	000002			MOV R0,SIZE(R1)	;SIZE[new size header] ← correct size
	012004	005061	000004			CLR NALLOC(R1)	;NALLOC[new size header] ← 0
	012010	005061	000006			CLR BLKLST(R1)	;BLKLST[new size header] ← 0
					;At this point, we have found a size header of the right size.
					;R0 = size, R1 = LOC[size header found]
	012014	006100			GTSZFD:	ROL R0		;R0 ← desired size in BYTES.
	012016	016103	000006			MOV BLKLST(R1),R3;R3 ← LOC[block to try]
	012022	001407				BEQ GTNWBL	;If no more blocks, then get a new one.
	012024	022763	177777	000002	GT5:	CMP #-1,MASK(R3);Is this block full?
	012032	001033				BNE GDBLK	;No.  Can use it.
	012034	016303	000000			MOV NEXTB(R3),R3;Yes.  Get another block.
	012040	001371				BNE GT5		;If there is one, try it.
	012042	006100			GTNWBL:	ROL R0		;Else need new block.
	012044	006100				ROL R0		;Recall:  R0 = 2*SIZE (since in bytes)
	012046	006100				ROL R0		;R0 ← 20*SIZE words
	012050	062700	000004			ADD #SIZBLH,R0	;R0 ← Size of block we need.
	012054	010102				MOV R1,R2	;R1 will be clobbered soon.  R2 ← LOC[size header].
	012056	004767	176612			JSR PC,GTFREE	;R0 ← LOC[new block]
	012062	016260	000006	000000		MOV BLKLST(R2),NEXTB(R0);NEXTB[block just made] ← LOC[first old block]
	012070	010062	000006			MOV R0,BLKLST(R2);BLKLST[size header] ← LOC[block just made]
	012074	005262	000004			INC NALLOC(R2)	;Just allocated a new block.
	012100	012760	100000	000004		MOV #100000,FRBIT(R0);Set its FRBIT arbitrarily.
	012106	016060	000004	000002		MOV FRBIT(R0),MASK(R0);We will assign this item to caller.
	012114	062700	000006			ADD #WORD0,R0	;R0 ← LOC[new item]
	012120	000423				BR  GTRET	;Prepare to return.
	012122	006063	000004		GDBLK:	ROR FRBIT(R3)	;Set FRBIT to next item.
	012126	036363	000004	000002		BIT FRBIT(R3),MASK(R3) ;Is this item available?
	PALX 222	09/12/74  01:24:20	PAGE 26
	HALTST PAL[HAL,HE]	PAGE 5.1 	Small block allocator

	012134	001372				BNE GDBLK		;No.  Try again.
	012136	056363	000004	000002		BIS FRBIT(R3),MASK(R3) ;Yes.  Set mask appropriately.
	012144	010302				MOV R3,R2	;
	012146	062702	000006			ADD #WORD0,R2	;R2 ← LOC[first item in block]
	012152	016303	000004			MOV FRBIT(R3),R3;R3 ← FRBIT.  We are about to calculate address of item.
	012156	100403				BMI GT3		;If R3 has 15 bit on, then R2 is right.
	012160	060002			GT4:	ADD R0,R2	;Else R2 ← LOC[next item in block]
	012162	006103				ROL R3		;
	012164	100375				BPL GT4		;Try again.
	012166	010200			GT3:	MOV R2,R0	;Almost done.  R0 ← LOC[found item]
	012170	012603			GTRET:	MOV (SP)+,R3	;Restore R3
	012172	012602				MOV (SP)+,R2	;Restore R2
	012174	000207				RTS PC		;Done.
	PALX 222	09/12/74  01:24:20	PAGE 27
	FREE PAL[HAL,HE]	PAGE 2.2 	Small block allocator

					
					
					; program initialization
					
		012176			.EVEN
	012176	000005			START:	RESET
	012200	012706	000500			MOV #500,SP	;initialize stack
	012204	005067	165566			CLR PS		;initialize processor status
	012210	005067	160330		CLKIN:	CLR CLKCNT	;clear clock registers- trap restart
	012214	005067	160322			CLR CLKSET
	012220	005067	160314			CLR CLKS
					
					
	012224	005003				CLR R3		;Count of how many times we have tried it
	012226	012700	000010		TEST:	MOV #10,R0
	012232	004767	177452			JSR PC,GTITEM	;Try to get some storage
	012236	005203				INC R3
	012240	000772				BR  TEST	;Loop around
RESTRT		12242	2	25	FRINIT	UNDEFINED
RESTRT		12242	2	25	MISSING COMMA
RESTRT		12242	2	25	NULL IMMED. OPERAND
	012242	004067	165532		RESTRT:	JSR FRINIT	;Reestablish free storage
						HALERR TSTDON	;Finished here.  Terminate cleanly.
						CRLF		;
						OUTSTR CRLFX	;Carriage return, line feed.
	012246	010046				MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	012250	010146				MOV R1,-(SP)	;Save R1.
	012252	012700	000626			MOV #CRLFX,R0	;Load up the string to be output
	012256	004767	166216			JSR PC,TYPSTR	;Call the string output utility routine.
	012262	012601				MOV (SP)+,R1	;Restore R1.
	012264	012602				MOV (SP)+,R2	;Restore R2.
						OUTSTR TSTDON	;
	012266	010046				MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	012270	010146				MOV R1,-(SP)	;Save R1.
	012272	012700	012334			MOV #TSTDON,R0	;Load up the string to be output
	012276	004767	166176			JSR PC,TYPSTR	;Call the string output utility routine.
	012302	012601				MOV (SP)+,R1	;Restore R1.
	012304	012602				MOV (SP)+,R2	;Restore R2.
						OUTSTR RUGMES	;
	012306	010046				MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	012310	010146				MOV R1,-(SP)	;Save R1.
	012312	012700	000631			MOV #RUGMES,R0	;Load up the string to be output
	012316	004767	166156			JSR PC,TYPSTR	;Call the string output utility routine.
	012322	012601				MOV (SP)+,R1	;Restore R1.
	012324	012602				MOV (SP)+,R2	;Restore R2.
	012326	000167	035446			JMP RUG		;Go directly to RUG.
	012332	000775				BR .-4		;In case we return.
					TSTDON:	ASCIE /Done./
	012334	   104		
	PALX 222	09/12/74  01:24:20	PAGE 28
	FREE PAL[HAL,HE]	PAGE 2.3 	Small block allocator

	012335	   157		
	012336	   156		
	012337	   145		
	012340	   056		
	012341	   000		
						.ASCIZ /Done./
		012342				.EVEN
		012176			.END START
	PALX 222	09/12/74  01:24:20	PAGE 29
	FREE PAL[HAL,HE]	PAGE 2 	***SYMBOL TABLE***      

	BLKLST	000006H		INVMRK	000004H		START	012176	
	CHGCOD	000002H		KBIR	177562		STRT11	000500	
	CLKCNT	172544		KBIS	177560		SZHH	011706	
	CLKIN	012210		KBOR	177566		TEST	012226	
	CLKS	172540		KBOS	177564		TSLOOP	000504	
	CLKSET	172542		LINKB	000004H		TSTDON	012334	
	CLKTRP	000104		LINKF	000002H		TYPCHR	000566	
	CRLFX	000626		MARK0	006400		TYPDEC	000516	
	DATUM	000000H		MARK1	006401		TYPDIG	000536	
	ERRTRP	000004		MARK2	006402		TYPOCT	000526	
	FEXACT	011020		MARK3	006403		TYPOUT	000560	
	FFOUND	010752		MARK4	006404		TYPRET	000624	
	FORM	000004H		MARK5	006405		TYPSTR	000500	
	FR1	010742		MASK	000002H		WORD0	000006H	
	FR2	010724		MERGR	011362	
	FRBIT	000004H		NALLOC	000004H	
	FREEND	010670		NEEDED	000002H	
	FREEPT	000666		NEXTB	000000H	
	FREERR	011032		NXTCHG	000000H	
	FREEST	000672		NXTCLC	000000H	
	FREL	004000		NXTGN	000000H	
	FRINIT	000000U		NXTSH	000000H	
	FRMS1	011206		OBUF	000160	
	FRMS2	011262		PC	000007R	
	FROVFL	011120		PRVGN	000002H	
	FRPOS	010740		PS	177776	
	FRRET	011012		R0	000000R	
	FRTRY	010712		R1	000001R	
	GDBLK	012122		R2	000002R	
	GNCHGS	000014H		R3	000003R	
	GNCLCS	000012H		R4	000004R	
	GNDEPS	000010H		RADIX	000544	
	GNVAL	000006H		RESTRT	012242	
	GT1	011726		RF	000005R	
	GT3	012166		RL1	011402	
	GT4	012160		RLFER1	011412	
	GT5	012024		RLFER2	011500	
	GTFREE	010674		RLFREE	011312	
	GTITEM	011710		RLMS1	011566	
	GTNWBL	012042		RLMS2	011635	
	GTNWSH	011750		RLRET	011404	
	GTRET	012170		RUG	050000	
	GTSZFD	012014		RUGMES	000631	
	HCOR	077776		SIZBLH	000004	
	IBUF	000150		SIZE	000002H	
	II	000010H		SIZSH	000004	
	ILGINS	000010		SP	000006R	
	PALX 222	09/12/74  01:24:20	PAGE 30
	FREE PAL[HAL,HE]	PAGE 2 	***SYMBOL TABLE***      


5 ERRORS DETECTED

1.4 WDS AVG INSN LENGTH

9 SECONDS RUN-TIME